/** container.d - 

// Written in the D programming language 1.0

Authors:
	Wei Li (oldrev@gmail.com)

Copyright:
	Copyright (C) 2007 Wei Li.

License:
	BSD

*/

module dotmars.base.collection.container;

// Aspects for container
////////////////////////////////////////////////////////////////////////////////

template OpCatAssignAspect(Cont)
{
	Cont opCatAssign(Cont.ValueType rhs)
	{
		addLast(rhs);
		return this;
	}

	Cont opCatAssign(Cont rhs)
	{
		Cont.Iterator it = rhs.begin();
		for(; it != rhs.end(); ++it)
			addLast(it.value());
		return this;
	}
}


template OpApplyAspect(Cont)
{
    int opApply(int delegate(ref Cont.ValueType val) proc)
	in {
		assert(proc !is null);
	}
	body {
        int result;
        for(Cont.Iterator i = begin; i != end; ++i)
        {
            result = proc(*i.ptr());
            if(result)break;
        }
        return result;
    }

}


template OpApplyReverseAspect(Cont)
{
    public int opApplyReverse(int delegate(ref Cont.ValueType val) proc)
	in {
		assert(proc !is null);
	}
	body {
        int result;
        for(Cont.ReverseIterator i = rbegin; i != rend; ++i)
        {
            result = proc(*i.ptr());
            if(result)break;
        }
        return result;
    }
}
